﻿<html>

	<head>
		<title>订单管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link href="../../css/dialog.css" rel="stylesheet">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerPopupEdit.js"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerMenu.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/JS/layout.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		<script src="../../js/datetool.js" type="text/javascript"></script>
		<style>
			body {
				height: 100%;
			}
		</style>
		<script type="text/javascript">
			var manager;
			var Fstatus = $api.getparastr("status");
			$(document).hover(parent.hindMenu);
			var saleUrl = BaseUrl + "Sale?token=" + $api.getStorage("token");
			$(function() {
				$("form").ligerForm();
				if($api.isEmpty(Fstatus)) Fstatus = 0;
				else
					$("#Fstatus").val(Fstatus);
				initContorl();
				initView();

			});

			function initView() {
				var url = saleUrl + "&PsType=0&Fstatus=" + Fstatus + "&Fkey=&Fsdt=" + $("#sdt").val() + "&Fedt=" + $("#edt").val();
				manager = $("#maingrid").ligerGrid({
					columns: [{
							display: '商品',
							width: 380,
							align: 'left',
							render: function(rowdata, rowindex, value) {
								if(rowdata.IsHead) {
									rowdata.Head.Fdate = rowdata.Head.Fdate.replace("T", " ");
									var i = rowdata.Head.Fdate.indexOf('.');
									rowdata.Head.Fdate = rowdata.Head.Fdate.substr(0, i);
									return '<span style="font-weight:bold;margin-right:5px;">' + rowdata.Head.Fdate + '</span> 订单号:' + rowdata.Head.Fcode;
								} else {
									//									var Fattr = "";
									//									var arr;
									//									if(rowdata.Detail.Fattr) {
									//										arr = JSON.parse(rowdata.Detail.Fattr);
									//									}
									//									for(var i in arr) {
									//										var row = arr[i];
									//										Fattr += row.Fattr + ":" + row.Fvalue + "；";
									//									}
									var ret = "<div style='margin:5px;height:120px;'><img src=" + rowdata.Detail.Fimg + " class='listimgs' style='float:left;top:5px' />";
									ret += "<div style='float:left; margin-left:5px'><span>【" + rowdata.Detail.Fsendnum + "】" + rowdata.Detail.Fpname + "</span><br/>";
									if(!$api.isEmpty(rowdata.Detail.Fmemo))
										ret += "<span style='color:#999'>" + rowdata.Detail.Fmemo + "</span><br/>";
									ret += "<span style='color:#999'>来源:" + Fstorename + "</span>"
									ret += "<div><div>"
									return ret;
								}
							}
						},
						{
							display: '销售单价',
							name: 'salePrice',
							width: 120,
							align: 'center',
							render: function(rowdata, rowindex, value) {
								if(rowdata.IsHead) {
									return "买家：" + "[" + rowdata.Head.Fnation + "]" + rowdata.Head.FloginName;
								}
								return "￥" + $api.toMoney(rowdata.Detail.Fprice);
							}
						},
						{
							display: '数量',
							name: 'Num',
							width: 100,
							align: 'center',
							render: function(rowdata, rowindex, value) {
								if(rowdata.IsHead) {
									return rowdata.Head.FfirstName + " " + rowdata.Head.FlastName;
								}
								return rowdata.Detail.Fnum + "件";
							}
						},
						{
							display: '实付款',
							name: 'PayMoney',
							width: 120,
							render: function(rowdata, rowindex, value) {
								if(!rowdata.IsHead && rowdata.Head) {
									return "账单金额:" + rowdata.Head.Ftotalmoney.toFixed(2) + "<br/>" +
										"折扣金额:" + rowdata.Head.Fdismoney.toFixed(2) + "<br/>" +
										"实付金额:" + (rowdata.Head.Ftotalmoney - rowdata.Head.Fdismoney).toFixed(2);
								}
								return "";
							}
						},
						{
							display: '配送状态',
							name: 'Fpsstatus',
							width: 120,
							render: function(rowdata, rowindex, value) {

								if(!rowdata.IsHead && rowdata.Head) {
									let ret = '';
									if(rowdata.Head.Fisback == 1) {
										ret = "【有退货】";
									}
									if(rowdata.Head.Fstatus == 2)
										return "待收货" + ret;
									else if(rowdata.Head.Fstatus == 3)
										return "部分待收货" + ret;
									else if(rowdata.Head.Fstatus == 4)
										return "待收货" + ret;
									else if(rowdata.Head.Fstatus == 5)
										return "已发货" + ret;
									else if(rowdata.Head.Fstatus == 6)
										return "已完成" + ret;
								}
								return "";
							}
						},
						{
							display: '商品操作',
							name: 'handler',
							width: 100,
							align: 'center',
							render: function(rowdata, rowindex, value) {
								if(!rowdata.IsHead && rowdata.Head) {
									var ret = "";
									//非活动订单
									if(rowdata.Head.Faid == 0) {
										//已付款待发货，已发部分货
										if(rowdata.Head.Fstatus == 4) {
											ret += "<a class='listbtn' style='width:75px;;display:block;' onclick='SendDriver(" + rowindex + ");'>确认发货</a>" +
										}
										if(rowdata.Head.Fstatus == 5) {
											ret += "<a class='listbtn' style='width:75px;;display:block;' onclick='Config(" + rowindex + ");'>确认客户收货</a>" +
										}
									}

									if(rowdata.Head.Fisback == 1)
										ret += "<a class='listbtn'  style='width:75px;;margin-top:5px;color:#fff;display:block;' onclick='ReturnDetail(" + rowindex + ");'>退货详情</a>";

									ret += "<a class='listbtn' style='width:75px;;margin-top:5px;color:#fff;display:block;'  onclick='Detail(" + rowindex + ");' >订单详情</a>";

									return ret;
								}

								return "";
							}
						},
						{
							display: '收货信息',
							name: 'DriverDetail',
							minWidth: 220,
							align: 'left',
							render: function(rowdata, rowindex, value) {
								if(!rowdata.IsHead && rowdata.Head) {
									if(rowdata.Head.Fdeliverytype == 1)
										return "收件人:" + rowdata.Head.Fname +
											"<br/>联系电话:" + rowdata.Head.Fmobile +
											"<br/>收件地址:" + rowdata.Head.Fprovince + rowdata.Head.Fcity + rowdata.Head.Fzone + rowdata.Head.Faddress;
									else {
										if(rowdata.Head.Fdeliverytype == 11)
											return "海运";
										else if(rowdata.Head.Fdeliverytype == 12)
											return "空运";
										else if(rowdata.Head.Fdeliverytype == 13)
											return "陆运";
									}
								}
								return "";
							}
						}
					],
					url: url,
					dataAction: 'server',
					width: '100%',
					height: 'auto',
					isScroll: true,
					method: 'get',
					rowHeight: "auto",
					pageSize: 20,
					rowAttrRender: function(rowdata, rowid) {
						if(rowdata.IsHead) {
							return "style='background:#f3f3f3;'";
						}
					},
					usePager: true, //是否分页  
					onDblClickRow: function(data, rowindex, rowobj) {
						if(rowdata.Head)
							parent.f_addTab(-1, '订单详情', 'vstore/tb_sale/Detail.html?Fcode=' + data.Head.Fcode);
						else
							parent.f_addTab(-1, '订单详情', 'vstore/tb_sale/Detail.html?Fcode=' + data.Fcode);
					}
				});

			}

			var sdtManger, edtManager, popZtid, popFaid;
			var popActivity, popPs;

			function initContorl() {
				sdtManger = $("#sdt").ligerGetDateEditorManager({
					absolute: false,
					format: "yyyy-MM-dd"
				});
				edtManager = $("#edt").ligerGetDateEditorManager({
					absolute: false,
					format: "yyyy-MM-dd"
				});

				var dataUtil = new datetool();

				var dateEnd = dataUtil.getNowFormatDate(0);  
				var dateStart = dataUtil.getNowFormatDate(24 * 60 * 60 * 1000 * 30);

				  
				$("#sdt").val(dateStart);  
				$("#edt").val(dateEnd);

				popPs = $("#Fpstype").ligerComboBox({
					ajaxType: 'get',
					valueField: 'Fid',
					textField: 'Fname',
					onSelected: function(newvalue) {
						if(newvalue == 2) {
							$("#Fzt").css("display", "block");
						} else
							$("#Fzt").css("display", "none");
					}
				});

			}

			//发货
			function SendDriver(i) {
				var row = manager.getRow(i);
				$.ligerDialog.confirm("确认已发货？", function(yes) {
					if(yes) {
						var url = BaseUrl + "sale/send?token=" + $api.getStorage("token") + "&code=" + row.Fcode;
						var param = {

						}
						$api.ajaxapp2(url, param, function(data) {
							top.$.ligerDialog.error("发货成功！", function() {
								manager.reload(true);
							});
						});
					}
				});
			}
			//确认收货
			function Config(i) {

				var row = manager.getRow(i);
				$.ligerDialog.confirm("确认客户已签收？", function(yes) {
					if(yes) {
						var url = BaseUrl + "sale/config?token=" + $api.getStorage("token") + "&code=" + row.Fcode;
						var param = {

						}
						$api.ajaxapp2(url, param, function(data) {
							top.$.ligerDialog.error("确认收货成功！", function() {
								manager.reload(true);
							});
						});
					}
				});
			}

			//退货
			//			function Return(i) {
			//				var row = manager.getRow(i);
			//				parent.f_addTab(-1, '订单退货', "vsys/tb_sale/Return.html?Fcode=" + row.Head.Fcode);
			//
			//			}

			function Detail(i) {
				var row = manager.getRow(i);
				parent.f_addTab(-1, '订单详情', "vsys/tb_sale/Detail.html?Fcode=" + row.Head.Fcode);
			}

			function ReturnDetail(i) {
				var row = manager.getRow(i);
				parent.f_addTab(-1, '退货详情', "vsys/tb_sale/ReturnDetail.html?Fcode=" + row.Head.Fcode);
			}

			function doSearch() {
				var url = saleUrl +
					"&PsType=" + popPs.getValue() +
					"&Fstatus=" + $("#Fstatus").val() +
					"&Fkey=" + $("#Fkey").val() +
					"&Fsdt=" + $("#sdt").val() +
					"&Fedt=" + $("#edt").val();

				manager.GetDataByURL(url);
			}
		</script>

	</head>
	<style>
		.dt {
			width: 60px;
		}
		
		.dd {
			margin-left: 70px;
		}
	</style>

	<body class="mainbody">
		<form id="form1" onsubmit="return false">
			<div>
				<div class="toolbar">
					<div class="div-content">
						<dl>
							<dt style="width: 60px;">时间区间</dt>
							<dd style="margin-left: 70px;">
								<div style="float:left"> <input type="text" id="sdt" name="sdt" ltype="date" ligerui="{width:120}" />
								</div>
								<div style="float:left;margin: 0 10px;"> 至 </div>
								<div style="float:left">
									<input type="text" id="edt" name="edt" ltype="date" ligerui="{width:120}" /></div>

							</dd>
							<dt style="width: 60px;">订单状态</dt>
							<dd style="margin-left: 70px;">
								<div style="margin-left: 10px;float:left;">
									<select name="Fstatus" id="Fstatus" ltype="select" ligerui="{width:120}">
										<option value="0" selected="selected">全部</option>
										<option value="2">待收货</option>
										<option value="3">部分待收货</option>
										<option value="4">待收货确认</option>
										<option value="5">已发货</option>
										<option value="6">已完成</option>
									</select>

								</div>

							</dd>
							<dt style="width: 60px;">配送方式</dt>
							<dd style="margin-left: 70px;">
								<div style="margin-left: 10px;float:left;">
									<select name="Fpstype" id="Fpstype" ltype="select" ligerui="{width:120}">
										<option value="0" selected="selected">全部</option>
										<option value="1">配送</option>
										<option value="11">海运</option>
										<option value="12">空运</option>
										<option value="13">路运</option>
									</select>
								</div>

							</dd>
						</dl>
						<dl>

							<dt style="width: 60px;">关键词</dt>
							<dd style="margin-left: 70px;">
								<div style="float:left;margin-left: 10px;"> <input type="text" placeholder="订单号" id="Fkey" name="Fkey" ltype="text" ligerui="{width:180}" />
								</div>
								<div style="float:left;margin-left: 10px;">
									<input style="display:inline" type="button" value="搜索" class="btn" onclick="doSearch();" />
								</div>
							</dd>
						</dl>
					</div>
				</div>
			</div>

			<div id="maingrid" style="background:#fff;"></div>

		</form>

	</body>

</html>